<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML3.2 EN">
<HTML>
<HEAD>
<META NAME="GENERATOR" CONTENT="DOCTEXT">
<TITLE>MPI_Buffer_detach</TITLE>
</HEAD>
<BODY BGCOLOR="FFFFFF">
<H1 id="MPI_Buffer_detach">MPI_Buffer_detach</H1>
Removes an existing buffer (for use in MPI_Bsend etc) 
<H2>Synopsis</H2>
<PRE>
</PRE>
<PRE>
int MPI_Buffer_detach(void *buffer_addr, int *size)
</PRE>

<PRE>
int MPI_Buffer_detach_c(void *buffer_addr, MPI_Count *size)
</PRE>

<P>
<H2>Output Parameters</H2>
<DL>
<DT><B>buffer_addr </B> <DD> initial buffer address (choice)

<DT><B>size </B> <DD> buffer size, in bytes (integer)
</DL>
<P>
<H2>Notes</H2>
The reason that <tt>MPI_Buffer_detach</tt> returns the address and size of the
buffer being detached is to allow nested libraries to replace and restore
the buffer.  For example, consider
<P>
<PRE>
    int size, mysize, idummy;
    void *ptr, *myptr, *dummy;
    MPI_Buffer_detach(&amp;ptr, &amp;size);
    MPI_Buffer_attach(myptr, mysize);
    ...
    ... library code ...
    ...
    MPI_Buffer_detach(&amp;dummy, &amp;idummy);
    MPI_Buffer_attach(ptr, size);
</PRE>

<P>
This is much like the action of the Unix signal routine and has the same
strengths (it is simple) and weaknesses (it only works for nested usages).
<P>
Note that for this approach to work, MPI_Buffer_detach must return MPI_SUCCESS
even when there is no buffer to detach.  In that case, it returns a size of
zero.  The MPI 1.1 standard for <tt>MPI_BUFFER_DETACH</tt> contains the text
<P>
<PRE>
   The statements made in this section describe the behavior of MPI for
   buffered-mode sends. When no buffer is currently associated, MPI behaves
   as if a zero-sized buffer is associated with the process.
</PRE>

<P>
This could be read as applying only to the various Bsend routines.  This
implementation takes the position that this applies to <tt>MPI_BUFFER_DETACH
</tt>as well.
<P>
<H2>Thread and Interrupt Safety</H2>
<P>
The user is responsible for ensuring that multiple threads do not try to
update the same MPI object from different threads.  This routine should
not be used from within a signal handler.
<P>
The MPI standard defined a thread-safe interface but this does not
mean that all routines may be called without any thread locks.  For
example, two threads must not attempt to change the contents of the
same <tt>MPI_Info</tt> object concurrently.  The user is responsible in this
case for using some mechanism, such as thread locks, to ensure that
only one thread at a time makes use of this routine.
Because the buffer for buffered sends (e.g., <tt>MPI_Bsend</tt>) is shared by all
threads in a process, the user is responsible for ensuring that only
one thread at a time calls this routine or <tt>MPI_Buffer_attach</tt>.
<P>
<H2>Notes for Fortran</H2>
All MPI routines in Fortran (except for <tt>MPI_WTIME</tt> and <tt>MPI_WTICK</tt>) have
an additional argument <tt>ierr</tt> at the end of the argument list.  <tt>ierr
</tt>is an integer and has the same meaning as the return value of the routine
in C.  In Fortran, MPI routines are subroutines, and are invoked with the
<tt>call</tt> statement.
<P>
All MPI objects (e.g., <tt>MPI_Datatype</tt>, <tt>MPI_Comm</tt>) are of type <tt>INTEGER
</tt>in Fortran.
<P>
The Fortran binding for this routine is different.  Because Fortran
does not have pointers, it is impossible to provide a way to use the
output of this routine to exchange buffers.  In this case, only the
size field is set.
<P>
<H2>Notes for C</H2>
Even though the <tt>bufferptr</tt> argument is declared as <tt>void *</tt>, it is
really the address of a void pointer.  See the rationale in the
standard for more details.
<P>
<H2>Errors</H2>
<P>
All MPI routines (except <tt>MPI_Wtime</tt> and <tt>MPI_Wtick</tt>) return an error value;
C routines as the value of the function and Fortran routines in the last
argument.  Before the value is returned, the current MPI error handler is
called.  By default, this error handler aborts the MPI job.  The error handler
may be changed with <tt>MPI_Comm_set_errhandler</tt> (for communicators),
<tt>MPI_File_set_errhandler</tt> (for files), and <tt>MPI_Win_set_errhandler</tt> (for
RMA windows).  The MPI-1 routine <tt>MPI_Errhandler_set</tt> may be used but
its use is deprecated.  The predefined error handler
<tt>MPI_ERRORS_RETURN</tt> may be used to cause error values to be returned.
Note that MPI does <em>not</em> guarantee that an MPI program can continue past
an error; however, MPI implementations will attempt to continue whenever
possible.
<P>
<DL>
<DT><B>MPI_SUCCESS </B> <DD> No error; MPI routine completed successfully.
</DL>
<DL>
<DT><B>MPI_ERR_ARG </B> <DD> Invalid argument.  Some argument is invalid and is not
identified by a specific error class (e.g., <tt>MPI_ERR_RANK</tt>).
</DL>
<DL>
<DT><B>MPI_ERR_OTHER </B> <DD> Other error; use <tt>MPI_Error_string</tt> to get more information
about this error code. 
</DL>
<P>
<H2>See Also</H2>
 MPI_Buffer_attach
<br>
</BODY></HTML>
